package com.iogame.iogamevalidatortest.javaxserver;

import com.iohao.game.action.skeleton.core.BarSkeleton;
import com.iohao.game.action.skeleton.core.BarSkeletonBuilderParamConfig;
import com.iohao.game.action.skeleton.core.flow.interal.DebugInOut;
import com.iohao.game.bolt.broker.client.AbstractBrokerClientStartup;
import com.iohao.game.bolt.broker.core.client.BrokerAddress;
import com.iohao.game.bolt.broker.core.client.BrokerClient;
import com.iohao.game.bolt.broker.core.client.BrokerClientBuilder;
import com.iohao.game.common.kit.NetworkKit;

public class DemoLogicServer extends AbstractBrokerClientStartup {
    /**
     * 初始化 业务框架
     * <pre>
     *     如果不需要业务框架的逻辑服，使用下面的示例代码
     *     {@code return BarSkeleton.newBuilder().build();}
     * </pre>
     *
     * @return 业务框架
     */
    @Override
    public BarSkeleton createBarSkeleton() {
        var config = new BarSkeletonBuilderParamConfig()
                .addActionController(DemoAction.class);        // 业务框架构建器

        var builder = config.createBuilder();
        builder.getSetting().setValidator(true);    // 开启参数校验
        // 添加控制台输出插件
        builder.addInOut(new DebugInOut());
        return builder.build();

    }

    /**
     * BoltBrokerClient 构建器
     *
     * <pre>
     *
     *     see {@link AbstractBrokerClientStartup#setBrokerClientBuilder(BrokerClientBuilder)}
     * </pre>
     *
     * @return 构建器
     */
    @Override
    public BrokerClientBuilder createBrokerClientBuilder() {
        BrokerClientBuilder builder = BrokerClient.newBuilder();
        builder.appName("Javax验证Demo逻辑服务");
        return builder;
    }

    @Override
    public BrokerAddress createBrokerAddress() {
        // 类似 127.0.0.1 ，但这里是本机的 ip
        String localIp = NetworkKit.LOCAL_IP;
        // broker （游戏网关）默认端口
        int brokerPort = 10200;
        return new BrokerAddress(localIp, brokerPort);
    }
}
